/**
 * Created by smp on 2017/5/5.
 */
var modelPath=ROOT_PATH+'/majorHazard/deviceLocation/';
$(function () {
    $('#unitId').combotree({
        url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0'
    });
    //初始化加载datagrid
    $('#dg1').datagrid({
        method: 'post',
        url: modelPath + 'list.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'asc'
        },
        // idField: 'id',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect:false,
        sortOrder: true,
        striped: true,
        fit: true,
        columns: [[
            {field: 'id', width: 80, checkbox: true},
            {field: 'name', title: '装置/部位名称', width: 100,  sortable: true},
            {field: 'code', title: '装置/部位代码', width: 80,  sortable: true},
            {field: 'enable', title: '是否启用', width: 80,  formatter:function(value,row,index){
                if(value==0){
                    return "否";
                }else{
                    return "是";
                }
            }},
            {field: 'unitCode', title: '所属单位编码', width: 80, sortable: true},
            {field: 'unitName', title: '所属单位名称', width: 60, sortable: true}
        ]],
        toolbar: '#toolbar'
    });
    //选择按钮事件
    $('#btn_select').on('click',function () {

        var checkedRows=$('#dg1').datagrid('getChecked');

        if(checkedRows.length == 0){
            layer.alert("选择需要编辑的行！");
            return
        }
        WindowManager.closeLayer({
            returnValue: checkedRows
        });
    });
    /**
     * 查询按钮
     */
    $('#selectDeviceLocation').on('click',function(){
        var name=$('#name').textbox("getValue");
        var code=$('#code').textbox("getValue");
        var unitId=$("#unitId").combobox("getValue");
        $('#dg1').datagrid('load', {name:name,code:code,unitId:unitId,sort: 'addTime', order: 'desc'});
    });
    $('#btn_clear').on("click", function () {
        $('#tb1').form('reset');
    });
});